package com.lushuan.springboot_lushuan.exception;

import com.lushuan.springboot_lushuan.pojo.ResponseMessage;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.net.http.HttpRequest;

@RestControllerAdvice  // 异常统一处理
public class GlobalExceptionHandlerAdvice {

    Logger logger = LoggerFactory.getLogger(GlobalExceptionHandlerAdvice.class);

    @ExceptionHandler({Exception.class})  // 什么异常进行统一处理
    public ResponseMessage handlerException(Exception e, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        logger.error("统一异常",e);

        return new ResponseMessage(500, "error", null);
    }
}
